import { question } from "readline-sync";
import { Poker } from "./poker.js";

let mapPrize = new Map()
mapPrize.set('同花顺', 100)
mapPrize.set('四条', 25)
mapPrize.set('满堂红', 10)
mapPrize.set('同花', 5)
mapPrize.set('顺子', 4)
mapPrize.set('三条', 3)
mapPrize.set('两对', 2)
mapPrize.set('一对', -1)
mapPrize.set('无对', -2)
let poker = new Poker()
let score = 100
while (true) {
    let bet_times = question('please give your bet:')//赌注押的倍数bet_times
    score = score-bet_times
    console.log(`您当前的分数是：${score}`);
    let one_hand = poker.get_one_hand()
    poker.output_onehand(one_hand)
    console.log();
    let swap_cards = question('\n please input card no what you wang to change(1-5),if you input 0,then game over,split by blank space:\n')
    if (swap_cards === '0') {//停止游戏
        console.log('游戏结束！');
        break
    }
    if (swap_cards.length !== 0){//玩家不想换牌，只是输入了一个回车,回车时值为0
    let swap_cards_arr = swap_cards.split(' ')
    let begin_index = 5
    for (let card_index of swap_cards_arr) {
        card_index--
        one_hand.splice(card_index, 1, poker.get_one_card(begin_index++))
    }
    poker.output_onehand(one_hand)
}
    let card_type = poker.get_type(one_hand)
    console.log();
    console.log(card_type);
    let tmp_score = mapPrize.get(card_type)
    console.log(tmp_score * bet_times);
    score += (tmp_score * bet_times)
}
